function [Vals, Keys, Stamps] = parseLog(LogPath)
%[Vals,Keys,Stamps]=parseLog(LogPath)
%Vals is an NxM array, where N is the number of log entries, M is the
%number of Keywords.
%Keys is a 1xM cell array of key words
%In log file, every image must have the same keywords.

%for parsing log files created with readfolder.m
try
    fid=fopen(LogPath, 'r');
    
    %parse log file and return array giving information of all files stored
    Keys=[];
    Vals=[];
    Stamps = {};
    if fid ~= -1
        try
            FirstLine = fgetl(fid);
            LineArray = strsplit(FirstLine, ',');
            Narray = length(LineArray);
            Ieven = 2:2:Narray;
            Iodd = 1:2:Narray - 1;
            Vals = cat(1, Vals, LineArray(Iodd));
            Keys = cat(1, Keys, LineArray(Ieven));
            
            while ~feof(fid)
                %get current line
                Line = fgetl(fid);
                LineArray = strsplit(Line,',');
                if length(LineArray) == Narray
                    Vals = cat(1, Vals, LineArray(Iodd));
                    Keys = cat(1, Keys, LineArray(Ieven));
                else
                end
            end
            
        catch Exception
            MsgString = getReport(Exception);
            disp(MsgString);
        end
        
        Stamps = Vals(:, 1);
        Vals=str2double(Vals(:, 2:end));
        Keys=Keys(1, 2:end);
    else
        warning('parseLog.m Failure when tried to open file %s.', LogPath)
        fclose('all');
    end
    
catch Exception
    MsgString = getReport(Exception);
    disp(MsgString);
    
	try
		fclose(fid);
    catch Exception
        MsgString = getReport(Exception);
        disp(MsgString);
	end

    Stamps = '';
    Vals = [];
    Keys = {};
end

